import DList from "@/components/dlist";
export default {
  data() {
    return {
      dividendShow:false,
      active: 1,
      tabsList: [
        {
          value: 1,
          name: "奖励记录",
          isShow: true
        },
        {
          value: 2,
          name: "服务记录",
          isShow: true
        },
        {
          value: 3,
          name: "绩效考核记录",
          isShow: true
        }
      ],
      reward_type_array: [],
      rewardType: 1,
      popupShow: false,
      detailList: [],
      allData: {},
      listData: [],
      loading: false,
      finished: false,
      info: false,
      page: 1,
      total: 0,
      isShowDirect: false, //直推人数
      subsidyData: null, //老板补贴升级记录
      average:0,
      dividend_list:[],
      dividend_total:1,
      dividend_page:1,
      dividend_load:true,
      type_card: 0
    };
  },
  // watch: {
  //   popupShow(newVal, oldVal) {
  //     if (newVal) {
  //       //滑动到底部触发事件
  //       this.$nextTick(() => {
  //         let unpackingGoods = document.getElementsByClassName("van-popup");
  //         unpackingGoods[0].onscroll = () => {
  //           let scrollHeight = unpackingGoods[0].scrollHeight;
  //           let clientHeight = unpackingGoods[0].clientHeight;
  //           let scrollTop = Math.round(unpackingGoods[0].scrollTop);
  //           if (scrollHeight == clientHeight + scrollTop) {
  //             if(this.i > 6) {
  //               console.log('已全部加载');
  //               return
  //             }
  //             this.detailList.push({
  //               id: this.i
  //             })
  //             this.i = this.i + 1;
  //             console.log(1111);
  //           }
  //         };
  //       });
  //     }
  //   }
  // },
  mounted() {
    this.getEntranceData();
  },
  methods: {
    async getEntranceData() {
      let data = await $http.get("plugin.link-move-two.frontend.home.index", { });
      if (data.result) {
        this.reward_type_array = data.data.reward_type_array;
        this.fun.setWXTitle(data.data.plugin_name);
        this.allData = data.data;
        this.rewardType = data.data.reward_type_array[0].value;
        this.info = true;
        if(data.data.hide_my_team) { 
          this.tabsList[1].isShow = false
        }else {
          this.tabsList[1].isShow = true
        }

        if(!data.data.star_subsidy_disable) {
          this.tabsList.push({
            value: 4,
            name: `${this.allData.boss_subsidy_name}升级记录`,
            isShow: true
          })
        }

        if(data.data.average_dividend){
            this.tabsList.push({
              value:5,
              name:data.data.average_dividend,
              isShow: true
            })
        }


        this.getIncomeRecordsData();
      } else {
        this.$toast(data.msg);
      }
    },
    // 获取收益记录
    async getIncomeRecordsData() {
      if (this.loading === true || this.finished === true) {
        return;
      }
      let json = {};
      let url = "";
      if (this.active == 1) {
        url = "plugin.link-move-two.frontend.home.get-reward";
        json = {
          page: this.page,
          // t: 1,
          reward_type: this.rewardType
        };
      } else if (this.active == 2) {
        url = "plugin.link-move-two.frontend.home.my-team";
        json = {
          page: this.page,
          // t: 1
        };
      } else if (this.active == 3) {
        url = "plugin.link-move-two.frontend.home.help-task";
        json = {
          page: this.page,
          // t: 1
        };
      } else if (this.active == 4) {
        url = "plugin.link-move-two.frontend.home.star-subsidy";
        json = {
          // page: this.page,
          // t: 1
        };
      } else if (this.active ==5) {
        url = "plugin.link-move-two-average-dividend.frontend.index.getList";
        json = {
          page: this.page,
          // t: 1
        };
      }
      this.loading = true;
      let { data, result, msg } = await $http.get(url, json);
      if (result === 0) {
        this.$toast(msg);
        return;
      }
      if(this.active == 4) {
        this.subsidyData  = data;
        this.subsidyData.see_dot_condition == 1 ? this.type_card = 0 : this.type_card = 1;
        return
      }
      if(this.active == 5){
        this.average = data.average;
      }
      if(this.active==5){
        if ( data.list.current_page === data.list.last_page) {
          this.finished = true;
        }
      }else{
        if (data.data.length === 0 || data.data.length < data.per_page || data.current_page === data.last_page) {
          this.finished = true;
        }
      }
      if(this.active == 5){
        this.total = data.list.total;
        this.listData.push(...data.list.data);
        // this.getLog();
      }else{
        this.total = data.total;
        this.listData.push(...data.data);
      }
      this.page++;
      this.isShowDirect = true;
      this.loading = false;
    },
    changeTab(value) {
      this.initData();
    },
    rewardEvent(item) {
      this.rewardType = item.value;
      this.initData();
    },
    onLoad() {
      this.getIncomeRecordsData();
    },
    initData() {
      this.loading = false;
      this.finished = false;
      this.page = 1;
      this.listData = [];
      this.isShowDirect = false;
      this.getIncomeRecordsData();
    },
    // 查看详情
    async showPopup(id,help_type) {
      let data = await $http.get("plugin.link-move-two.frontend.home.help-detail", { thaw_id: id,help_type});
      if (data.result) {
        this.detailList = data.data;
        this.popupShow = true;
      } else {
        this.$toast(data.msg);
      }
    },
    async dividendScroll(){
      if(this.dividend_page>=this.dividend_total){
        return;
      }
      if(this.dividend_load){
        this.dividend_load= false;
        let page = this.dividend_page+ 1;
        // this.getLog(page);
      }
    },
    opened(){
      if(this.$refs.dividendPopup){
        let  dom = this.$refs['dividendPopup'].$el;
        dom.addEventListener("scroll",this.dividendScroll);
      }
    },
    show_dividend(){
      this.dividendShow = true;
    },
    // getLog(page=1){
    //   $http.get("plugin.link-move-average-dividend.frontend.index.getLog",{page},'').then(({result,data,msg})=>{
    //     this.dividend_load = true;
    //     if(result){
    //       (page==1)?(this.dividend_list=data.data):(this.dividend_list=this.dividend_list.concat(data.data));
    //       this.dividend_total = data.last_page;
    //       this.dividend_page =  data.current_page;
    //       if(data.current_page==data.last_page){
    //         this.dividend_load = false;
    //       }
    //     }else{
    //       this.$toast(msg);
    //     }
    //   })
    // },
  },
  components: { DList }
};
